<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@include file="../../common/common.jsp" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
	<head>
		<meta charset="UTF-8">
		<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
		<title>云众科技网上预约挂号系统</title>
	</head>
	<body>
		<div class="container">
			<form class="form-horizontal text-center" style="position:relative;"  name="infoForm" action="javascript:doSub()" method="post" >
				<input type="hidden" name="roleId" value="${role.roleId}">
				<div class="container" >
					<div class="form-group" >
						<label class="control-label col-sm-2 col-md-2">角色名称:</label>
						<div class="col-md-4 col-sm-4">
							<input class="form-control" name="roleName" required value="${role.roleName}" placeholder="请输入角色姓名" onblur="checkRoleName(this)"/>
						</div>	
					</div>
					<div class="form-group">
						<label class="control-label col-sm-2 col-md-2">角色信息:</label>
						<div class="col-md-6 col-sm-6">
							<textarea class="form-control" name="roleInfo" rows="3" placeholder="请输角色信息" >${role.roleInfo }</textarea>
						</div>
					</div>
					<div class="form-group">
						<div class="col-lg-4 col-md-4 col-sm-2 col-xs-2">
							
						</div>
						<div class=" col-lg-4 col-md-4 col-sm-8 col-xs-8" >
							<div class="col-md-6 col-sm-6">
								<button class="form-control btn-primary" type="submit" >提交</button>
							</div>
							<div class="col-md-6 col-sm-6">
								<button class="form-control btn-primary" type="button" onclick="goBack()" >返回</button>
							</div>
						</div>
						<div class="col-lg-4 col-md-4 col-sm-2 col-xs-2">
							
						</div>
					</div>
				</div>
			</form>
			<hr/>
		</div>
	</body>
	<script type="text/javascript">
		
		//角色名称重复验证
		function checkRoleName(inputElement){
			var roleName = inputElement.value;
			$.ajax({
				url:"/sys/checkRoleName",
				data:{roleName:roleName,roleId:"${role.roleId}"},
				async:true,
				dataType:"json",
				success:function(msg){
					if(msg.result==false){
						inputElement.validity.patternMismatch = true;
						inputElement.setCustomValidity("角色名称已被占用!");
						return;
					}else{
						inputElement.validity.patternMismatch = false;
						inputElement.setCustomValidity("");
					}
				}
			});
		}
		//提交方法
		function doSub(){
			bootbox.confirm("确定要提交吗?", function(result) {
				if(result){
					$("form[name='infoForm']").attr("action","<%=request.getContextPath()%>/sys/saveOrUpdateRole");
					$("form[name='infoForm']").submit();
				}
			})
		}
		function goBack(){
			history.go(-1);
		}
	</script>
</html>